<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="com.google.appengine.api.datastore.Key"%>
<%@ page import="com.google.appengine.api.datastore.KeyFactory"%>
<%@ page import="appnode.SearchNode" %>
<%@ page import="appnode.Node" %>
<%@ page import="appnode.Msgtools" %>
<%@ page import="appnode.PMF" %>

<html>
<head>
	<link rel="stylesheet" href="map.css" type="text/css" media="screen" title="mapcss"></link>
	<link rel="stylerating" href="ratings.css" type="text/css" media="screen" title="ratecss"></link>
	<script type="text/javascript" src="ratings.js"></script>
	<title>Add ratting</title>
	<script>
	function checkform() {
		valid=true;
		if (document.input.com.value=="" || document.input.col.value=="" || document.input.exp.value==""){
			alert("Rate all");
			valid=false;	
		}
	return valid;
	}
	</script>
</head>
<body class="window">
<%

	String nodename = request.getParameter("nodename");
	String noderating = request.getParameter("noderating");

	/*Key keynodename = KeyFactory.stringToKey(nodename);
	Key keynoderating = KeyFactory.stringToKey(noderatings);*/
	
	String nodeowner = SearchNode.getByName(nodename).getOwner();
	String nodertowner = SearchNode.getByName(noderating).getOwner();
	
	/*Node node = pm.getObjectById(Node.class,keynodename);
	String nodeowner = node.getOwner();
	
	Node node1 = pm.getObjectById(Node.class,keynoderating);
	String nodertowner = node1.getOwner();*/
	
%>
<div class="openwindow">
Add ratings to the node : <%=noderating%><br>
Node's owner : <%=nodertowner%><p>

<%
	if (Msgtools.sentMsgowner(nodeowner,nodertowner).equals("yes")) {
%>
<table id="ratings">
	<tr>
		<td>
Communication
		</td>
		<td>
	<div class="rateMe" title="">
  	<a onclick="rateIt(com,'com',this)" id="com_1" title="1" onmouseover="rating(com,'com',this)" onmouseout="off(com,'com',this)"></a>
    <a onclick="rateIt(com,'com',this)" id="com_2" title="2" onmouseover="rating(com,'com',this)" onmouseout="off(com,'com',this)"></a>
    <a onclick="rateIt(com,'com',this)" id="com_3" title="3" onmouseover="rating(com,'com',this)" onmouseout="off(com,'com',this)"></a>
    <a onclick="rateIt(com,'com',this)" id="com_4" title="4" onmouseover="rating(com,'com',this)" onmouseout="off(com,'com',this)"></a>
    <a onclick="rateIt(com,'com',this)" id="com_5" title="5" onmouseover="rating(com,'com',this)" onmouseout="off(com,'com',this)"></a>
  </div>
		<td>
<span id="comrateStatus"></span>
<span id="comratingSaved">Rating Saved!</span>
		</td>
	</tr>
	
	<tr>
		<td>
Collaboration
		</td>
		<td>
<div class="rateMe" title="">
<a onclick="rateIt(col,'col',this)" id="col_1" title="1" onmouseover="rating(col,'col',this)" onmouseout="off(col,'col',this)"></a>
<a onclick="rateIt(col,'col',this)" id="col_2" title="2" onmouseover="rating(col,'col',this)" onmouseout="off(col,'col',this)"></a>
<a onclick="rateIt(col,'col',this)" id="col_3" title="3" onmouseover="rating(col,'col',this)" onmouseout="off(col,'col',this)"></a>
<a onclick="rateIt(col,'col',this)" id="col_4" title="4" onmouseover="rating(col,'col',this)" onmouseout="off(col,'col',this)"></a>
<a onclick="rateIt(col,'col',this)" id="col_5" title="5" onmouseover="rating(col,'col',this)" onmouseout="off(col,'col',this)"></a>
</div>
		</td>
		<td>
<span id="colrateStatus"></span>
<span id="colratingSaved">Rating Saved!</span>
		</td>
	</tr>
	
	<tr>
		<td>
Expert
		</td>
		<td>
<div class="rateMe" title="">
<a onclick="rateIt(exp,'exp',this)" id="exp_1" title="1" onmouseover="rating(exp,'exp',this)" onmouseout="off(exp,'exp',this)"></a>
<a onclick="rateIt(exp,'exp',this)" id="exp_2" title="2" onmouseover="rating(exp,'exp',this)" onmouseout="off(exp,'exp',this)"></a>
<a onclick="rateIt(exp,'exp',this)" id="exp_3" title="3" onmouseover="rating(exp,'exp',this)" onmouseout="off(exp,'exp',this)"></a>
<a onclick="rateIt(exp,'exp',this)" id="exp_4" title="4" onmouseover="rating(exp,'exp',this)" onmouseout="off(exp,'exp',this)"></a>
<a onclick="rateIt(exp,'exp',this)" id="exp_5" title="5" onmouseover="rating(exp,'exp',this)" onmouseout="off(exp,'exp',this)"></a>
</div>
		</td>
		<td>
<span id="exprateStatus"></span>
<span id="expratingSaved">Rating Saved!</span>
		</td>
	</tr>
</table>

<form name="input" action="/addrating" method="post" onsubmit="return checkform()">
	<input type="hidden" name="nodeowner" value="<%=nodeowner%>"></input> 
	<input type="hidden" name="nodertowner" value="<%=nodertowner%>"></input>
	<input type="hidden" name="nodename" value="<%=nodename%>"></input> 
	<input type="hidden" name="noderating" value="<%=noderating%>"></input> 
	<input type="hidden" name="com" value=""></input>
	<input type="hidden" name="col" value=""></input>
	<input type="hidden" name="exp" value=""></input>
	
<input type="submit" value="Add rating"/>
<input type="button" value="Cancel" onClick="self.close()"/>
</form>

<%
}
else {
	out.print("You can't add rating");
	out.print("<br>");
%>
	<input type="button" value="Close" onClick="self.close()"/>
<%
}

%>
</div>
</body>
</html>